<?php
include_once 'mysql.php';

class jawabanMurid
{
    private $nama;
    private $sekolah;
    private $kelas;
    private $jawaban = array();
    function setNama($nama){
            $this->nama = $nama;
    }
    function setSekolah($sekolah){
            $this->sekolah = $sekolah;
    }
    function setkelas($kelas){
            $this->kelas = $kelas;
    }
    function setJawaban($nomor,$jawab){
        if($nomor > 0)
            $this->jawaban[$nomor]=$jawab;
    }
    function getAllJawaban(){
        return $this->jawaban;
    }
    function setJumlahSoal($jumlah){
        $this->jawaban[0] = $jumlah;
    }
    function gettJumlahSoal(){
        if(isset($this->jawaban[0]))
            return $this->jawaban[0];
        else
            return 0;
    }
    function destroyJawaban(){
        unset ($jawaban);
    }
    function getSQLInsert(){
        global $tabel_murid;
        global $tabel_jawaban_murid;
        $jumlah = $this->jawaban[0];
        $text = "INSERT INTO $tabel_murid VALUES (NULL,'$this->nama','$this->sekolah','$this->kelas',curdate());";
        $text .= "INSERT INTO $tabel_jawaban_murid VALUES ";
        for ($i = 1 ; $i <= $jumlah;$i++){
            $text .= "(last_insert_id(),".$i.",".$this->jawaban[$i].")";
            if($i < $jumlah)
                $text .= ",";
        }
        $text .= ";";
        return $text;
    }
}
//insert into tabel (kol1,kol2,kol3) values (r1k1,r1k2,r3k3),(r2k1,r2k2,r2k3);
//isi tabel jawban : ID dari responden, nomor soal, jawaban
?>
